#include "Menu.h"

Menu::Menu(sf::RenderWindow& wnd) : currentItem(1), arrowOffset(100)
{
	if(!arrowTexture.loadFromFile("Assets/mouse.png"))
	{
		std::cout << "Could not load a menu asset";
	}
	arrowSprite.setTexture(arrowTexture);
	

	if(!menuFont.loadFromFile("Assets/CALIBRI.ttf"))
	{
		std::cout << "Could not load font";
	}

	if(!buffer.loadFromFile("Assets/MenuDing.wav"))
	{
		std::cout << "Could not load menu sound";
	}

	if(!menuMusic.openFromFile("Assets/Wreckage.ogg"))
	{
		std::cout << "Error loading menu music";
	}
	arrowTexture.setSmooth(true);
	//menuMusic.setLoop(true);
	menuding.setBuffer(buffer);
	startText.setFont(menuFont);
	optionsText.setFont(menuFont);
	startText.setString("Start");
	optionsText.setString("Options");
	startText.setPosition(400, 200);
	optionsText.setPosition(400,250);
	arrowSprite.setPosition(startText.getPosition().x + 100, startText.getPosition().y - 25);
	std::cout << "Menu init";
}

void Menu::startStopMusic(bool truefalse)
{
	if(truefalse == true)
		menuMusic.play();
	else if(truefalse == false)
	{
					menuMusic.pause();
					menuMusic.stop();
	}

}

void Menu::drawMenuElements(sf::RenderWindow& wnd)
{
	wnd.draw(arrowSprite);
	wnd.draw(startText);
	wnd.draw(optionsText);
}

void Menu::menuUpdate()
{
	if(currentItem == 1)
	{
		arrowSprite.setPosition(startText.getPosition().x + 100, startText.getPosition().y - 25);
		menuding.play();
	}
	else if(currentItem == 2)
	{
		arrowSprite.setPosition(optionsText.getPosition().x + 150, optionsText.getPosition().y - 25);
		menuding.play();
	}
	else if(currentItem >= 3) //If we hit down to many times and currentitems goes to 3 or above we set it back to options
	{
		currentItem = 2;
	}
	else if(currentItem <= 0) //If we hit up to many times and currenitem goes to 0 or below reset it to start
	{
		currentItem = 1;
	}
	

}

float Menu::getCurrentItem()
{
	return currentItem;
}

float Menu::setCurrentItem(float val)
{
	return currentItem = val;
}

sf::Text Menu::getStartText()
{
	return startText;
}

sf::Text Menu::getOptionsText()
{
	return optionsText;
}

sf::Sprite Menu::getArrowSprite()
{
	return arrowSprite;
}

sf::Font Menu::getFont()
{
	return menuFont;
}

